package thread;

import java.util.concurrent.ThreadPoolExecutor;

class MyRunnable implements Runnable{
    public void run(){
        while(true){
            System.out.println("Hello thread");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}

public class Demo2 {
    public static void main(String[] args) {
        //相当于通过runnable这个对象来进行线程的实际操作
        Runnable runnable = new MyRunnable();
        Thread t = new Thread(runnable);
        //run是一个回调函数，不需要手动调用，线程创建好了之后就会自动调用
        t.start();
        //t.run();

        while(true){
            System.out.println("Hello main");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
